package com.leo.erp.service.impl;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.leo.erp.dao.DepotItemDao;
import com.leo.erp.dto.DepotItemExecution;
import com.leo.erp.dto.MaterialExecution;
import com.leo.erp.dto.MaterialStockExecution;
import com.leo.erp.service.DepotItemService;
import com.leo.erp.service.MaterialService;
import com.leo.erp.service.MaterialStockService;
import com.leo.erp.util.GlobalRuntimeException;

@Service
public class DepotItemServiceImpl implements DepotItemService{
	@Autowired
	private DepotItemDao depotItemDao;
	@Autowired
	private MaterialStockService materialStockService;

	@Override
	public BigDecimal inOrOutPrice(String type, String subType, String MonthTime) {
		BigDecimal result= BigDecimal.ZERO;
        try{
            result = depotItemDao.inOrOutPrice(type, subType, MonthTime);
        }catch(GlobalRuntimeException e){
            e.printStackTrace();
        }
        return result;
	}

	/**
     * 库存统计
     * @param depotId
     * @param mId
     * @param beginTime
     * @param endTime
     * @return
     */
	@Override
	public DepotItemExecution getStockByParam(int depotId, int materialId, String beginTime, String endTime,
			int tenantId) {
		DepotItemExecution de = new DepotItemExecution();
		MaterialStockExecution me = materialStockService.getInitStockByMid(depotId, materialId);
		DepotItemExecution d = depotItemDao.getStockByParam(depotId, materialId, beginTime, endTime, tenantId);
		double inNum = d.getInNum();
		double outNum = d.getOutNum();
		double initStock = me.getKucun();
		de.setKucun((initStock + inNum) - outNum);
		return de;
	}
	
	
}
